package com.yueshop.seckill.config;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.io.IOException;


@Configuration
public class MyRedssionConfig {
    //所有的对Redisson操作都是使用RedissonClient对象
    @Bean(destroyMethod="shutdown")
    public RedissonClient redisson(@Value("${spring.redis.host}")String url) throws IOException {
        Config config = new Config();   // redis:// or rediss://
        //单实例节点
        config.useSingleServer().setAddress("redis://"+url+":6379");
        //根据config对象创建RedissonClient
        RedissonClient redisson = Redisson.create(config);
        return redisson;
    }
}
